import { Component, Injector, ViewEncapsulation } from '@angular/core';
import { Http } from '@angular/http';
import { VideoDto, EntityDtoOfInt64, HomePageServiceProxy, ArticleDto, TagDto } from '@shared/service-proxies/service-proxies';
import { NotifyService } from '@abp/notify/notify.service';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';
import { appModuleAnimation } from '@shared/animations/routerTransition';


@Component({
  templateUrl: './post.component.html',
  styleUrls: ['./post.component.css'],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})
export class PostComponent extends AppComponentBase {

  //Filters
  advancedFiltersAreShown = false;
  filterText = '';

  articles: ArticleDto[];
  tags: TagDto[];
  constructor(
    injector: Injector,
    private _http: Http,
    private _notifyService: NotifyService,
    private _homepage: HomePageServiceProxy
  ) {
    super(injector);
    this.getArticles();
    this.getTags();
  }

  getArticles() {
    this.articles = new Array<ArticleDto>();
    this._homepage.getArticles(
      undefined, 1000, 0
    ).subscribe(result => {
      this.articles = result.items;
      console.log(result.items);
    });
  }
  getTags(): void {
    this._homepage.getTags().subscribe(result => this.tags = result.items);
  }

  getArticleBy(id: number): void {
    this._homepage.getArticleByTagId(id, undefined, 1000, 0).subscribe(result => this.articles = result.items);
  }

}

